#-*-coding:utf-8-*-
import os
import sys
from PyQt5.QtCore import *
from PyQt5.QtWidgets import *
class UrlWindow(QWidget):

    def __init__(self,title,content,url):
        super(UrlWindow,self).__init__()
        self.url=url
        self.setWindowTitle(title)
        self.main_layout=QVBoxLayout()
        self.main_layout.setSpacing(15)
        self.content_label=QLabel(content)
        self.content_label.setAlignment(Qt.AlignCenter)
        self.url_btn=QPushButton(url)
        self.url_btn.setStyleSheet("QPushButton{color:#FF6600}"
                                  "QPushButton:hover{color:red}"
                                  "QPushButton{background-color:#D3D3D3}"
                                  "QPushButton{border:2px}"
                                  "QPushButton{border-radius:10px}"
                                  "QPushButton{padding:2px 4px}")
        self.url_btn.clicked.connect(self._openFile)
        self.dir_btn=QPushButton('打开输出目录')
        self.dir_btn.setStyleSheet("QPushButton{color:#20B2AA}"
                                  "QPushButton:hover{color:#FFD700}"
                                  "QPushButton{background-color:#D3D3D3}"
                                  "QPushButton{border:2px}"
                                  "QPushButton{border-radius:10px}"
                                  "QPushButton{padding:2px 4px}")
        self.dir_btn.clicked.connect(self._openDirectpath)
        self.main_layout.addWidget(self.content_label)
        self.main_layout.addWidget(self.url_btn)
        self.main_layout.addWidget(self.dir_btn)
        self.setLayout(self.main_layout)

    def _openFile(self):
        try:
            rp = self.url.replace("/", "\\")
            os.popen(r"explorer.exe  %s" % rp)
        except Exception as open_file_ERR:
            print(str(open_file_ERR))

    def _openDirectpath(self):
        try:
            dp=os.path.dirname(self.url)
            os.startfile(dp)
        except Exception as open_dir_ERR:
            print(str(open_dir_ERR))

if __name__ == '__main__':
    app=QApplication(sys.argv)
    u=UrlWindow('导出','导出成功',r'E:\中文路径输出测试\导出Excel到这里\场景8.xlsx')
    u.show()
    sys.exit(app.exec_())